package com.health.fragment.admindoc;

import java.util.List;

import com.health.viewscontrols.MainActivity_Menu_AdminDocter2;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity;
import com.health.R;
import com.health.viewscontrols.ShowJieLunPicActivity;
import com.health.adapter.AdminHomeListAdapter;
import com.health.adapter.MainMenuGridAdapter_Tj_JTYS;
import com.health.db.FDbManager;
import com.health.viewscontrols.focusgroup.FocusGroupMainActivity;
import com.health.fragment.NovaFragment;
import com.health.viewscontrols.photo.PhotoMainActivity2;
import com.health.viewscontrols.qyinfo.QYInfo;
import com.health.viewscontrols.sbcl.SBCLMainActivity2;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.viewscontrols.tijian.TiJianActivity;
import com.health.tools.SPUtil;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 健康管理界面(医生管理)
 * 
 * @author nova
 *
 */
public class AdminDocterHealthManage2 extends NovaFragment  {

	private GridView gd_menu;
	private MainMenuGridAdapter_Tj_JTYS menuAdapter;
	private ARCHIVE_BASEINFO userinfo = null;
	private View docHealthView;

	private TextView tv_name;
	private EditText ed_idcard;
	private EditText ed_name;
	private Button btn_search;
	private ListView tongji_list_lv;
	private AdminHomeListAdapter adminHealthAdapter = null;
	private FDbManager fdbmanger = null;
	@Override
	public View findViews(LayoutInflater inflater) {
		userinfo = NovaApplication.getUserInfo();
		fdbmanger = NovaApplication.fdbmanger;
		docHealthView = inflater.inflate(R.layout.qyinfo_main, null);
		initViews(docHealthView);

		return docHealthView;
	}

	@Override
	public void setupView(View view) {
		// TODO Auto-generated method stub

	}

	@Override
	public void addListener() {
		try {
			// 菜单选项
			gd_menu.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
					if( userinfo ==null){
						((MainActivity_Menu_AdminDocter2) getActivity()).showTextDialog("请选择会员");
						return;
					}
					
					Intent intent = null;
					if (position == 0) {
						// 0 "个人档案",
						intent = new Intent(getActivity(), PersonalFileActivity.class);
					} else if (position == 1) {
						// 1 "健康体检",
						intent = new Intent(getActivity(), TiJianActivity.class);
					} else if (position == 2) {
						// 2 "重点人群",
						intent = new Intent(getActivity(), FocusGroupMainActivity.class);
					} else if (position == 3) {
						intent = new Intent(getActivity(), ShowJieLunPicActivity.class);
					} else if (position == 4) {
						// 5拍取照片
						intent = new Intent(getActivity(), PhotoMainActivity2.class);
					} 
					else if (position == 5) {
					
						intent = new Intent(getActivity(), SBCLMainActivity2.class);
						
//						if(NovaApplication.bloothTool!=null){
//							NovaApplication.bloothTool.scanLeDevice(false); 
//						}
						
					}else if(position==6){
						intent = new Intent(getActivity(), QYInfo.class);
					}
					if(intent!=null){
						
						startActivity(intent);
					}
				}
			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public void setData() {
		String str_jdr = SPUtil.getstr_jdr(getActivity());
		String str_jdrno = SPUtil.getStr_jdrno(getActivity());
		
		final List<ARCHIVE_BASEINFO> infos = fdbmanger.findAllByWhere(ARCHIVE_BASEINFO.class,
				" CREATER='" + str_jdr + "' AND CREATED_BY='" + str_jdrno + "'");
		adminHealthAdapter = new AdminHomeListAdapter(getActivity(), infos);
		tongji_list_lv.setAdapter(adminHealthAdapter);
		tongji_list_lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				 userinfo=infos.get(position);
				 NovaApplication.setUserInfo(userinfo);
				 if(userinfo!=null){
						
						if (position % 2 == 0) {
							tv_name.setText("欢迎  " + userinfo.getCUSTOMERNAME()+"    已签约");
						} else {
							tv_name.setText("欢迎  " + userinfo.getCUSTOMERNAME()+"    未签约");
						}
				 }
			}
		});

	}

	/**
	 * 初始化布局
	 * 
	 * @author 王婷婷
	 * @date 2017年2月10日 下午3:17:44
	 */
	private void initViews(View v) {
		gd_menu = (GridView) v.findViewById(R.id.gd_menu);
		tv_name = (TextView) v.findViewById(R.id.tv_name);
		if(userinfo!=null){
			tv_name.setText("欢迎  " + userinfo.getCUSTOMERNAME());
		}
	
		menuAdapter = new MainMenuGridAdapter_Tj_JTYS(getActivity().getApplicationContext());
		gd_menu.setAdapter(menuAdapter);
		ed_idcard = (EditText) v.findViewById(R.id.ed_idcard);
		ed_name = (EditText) v.findViewById(R.id.ed_name);
		btn_search = (Button) v.findViewById(R.id.btn_search);
		tongji_list_lv=(ListView)v.findViewById(R.id.tongji_list_lv);
	}


	@Override
	public void setXueYang(String xueYang) {

	}
}
